<template>
	<view class="_content">
		<view class="_search">
			<view class="_input">
				<u-input type="text" placeholder="分类名称" />
			</view>
			<view class="_button">
				<text>搜索</text>
			</view>
		</view>

		<view class="_namePath">
			<!-- <template v-for="(item,index) in mNamePathList">
				<template v-if="index===1">
					<view>
						<text style="color: #2979FF;">{{item.name}}</text>
						>
					</view>
				</template>
				<template v-if="index === mNamePathList.length-1">
					<view>
						<text style="color: #2979FF;">{{item.name}}</text>
					</view>
				</template>
				<template v-else>
					<view @click="goToTypId(item.id)">
						<text style="color: #2979FF;">{{item.name}}</text>
						>
					</view>
				</template>
				
			</template> -->
			<text>当前选择:{{namePath}}</text>
		</view>

		<view class="_list">
			<u-radio-group>
				<template v-for="(item,index) in mListData">
					<view class="_listItem">
						<u-radio @change="radioChange" :name="item.id"></u-radio>
						<view @click="getNextList(item.id)">
							{{item.name}}
						</view>
					</view>
				</template>
			</u-radio-group>
		</view>

		<view class="_bottom">
			<u-button type="error" @click="typeSelectEnd">确定</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		name: "commodity-type-select",
		props: {
			listData: {
				type: Array,
				required: true,
			},
		},
		data() {
			return {
				mListData: this.listData,
				current: 0,
				namePath: "未选择",
			};
		},
		watch: {
			listData() {
				this.mListData = this.listData;
			}
		},
		methods: {
			radioChange(value) {
				for(let i=0;i<this.mListData.length;i++){
					if(this.mListData[i].id === value){
						this.namePath = this.mListData[i].namePath;
						break;
					}
				}
				this.$emit("itemClick", value);
			},
			typeSelectEnd() {
				this.$emit("typeSelectEndClick");
			},
			getNextList(typeId) {
				this.$emit("getNextListClick",typeId);
			},
			goToTypId(typeId){
				this.$emit("goToTypIdClick",typeId);
			}
		}
	}
</script>

<style lang="scss" scoped>
	._content {
		margin: 10rpx;
		display: flex;
		flex-direction: column;
		padding-bottom: 15rpx;

		._search {
			height: 75rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 10rpx;

			._input {
				border-style: solid;
				border-width: 1rpx;
				border-radius: 20rpx;
				border-color: #999999;
				width: 600rpx;
				padding: 5rpx;
			}

			._button {
				padding: 10rpx;
				background-color: #FA3534;
				color: #FFFFFF;
				width: 100rpx;
				height: 75rpx;
				border-radius: 15rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}

		._namePath {
			margin-top: 10rpx;
			height: 65rpx;
			font-size: 35rpx;
			background-color: #F5F5F5;
			padding: 10rpx;
			display: flex;
			flex-direction: row;
		}

		._list {
			margin-top: 10rpx;
			display: flex;
			flex-direction: column;

			._listItem {
				border-style: solid;
				border-width: 1rpx;
				border-radius: 5rpx;
				border-color: #E0E0E0;
				width: 720rpx;
				height: 85rpx;
				display: flex;
				align-items: center;
				padding: 10rpx;
				margin-bottom: 10rpx;
			}
		}

		._bottom {
			position: fixed;
			bottom: 10rpx;
			width: 720rpx;
		}
	}
</style>
